import 'package:flutter/material.dart';

class FooterButtonController extends ChangeNotifier {
  String confirmText = '确定';
  String cancelText = '取消';
  bool showCancelButton = true;
  bool showConfirmButton = true;
  bool isLoading = false;

  final Function onConfirm;
  final Function onCanCel;

  FooterButtonController({
    this.confirmText = '确定',
    this.cancelText = '取消',
    this.showCancelButton = true,
    this.showConfirmButton = true,
    this.isLoading = false,
    required this.onConfirm,
    required this.onCanCel,
  });

  void setConfirmText(String text) {
    confirmText = text;
    notifyListeners();
  }

  void setCancelText(String text) {
    cancelText = text;
    notifyListeners();
  }

  void setShowCancelButton(bool show) {
    showCancelButton = show;
    notifyListeners();
  }

  void setShowConfirmButton(bool show) {
    showConfirmButton = show;
    notifyListeners();
  }

  void setIsLoading(bool loading) {
    isLoading = loading;
    notifyListeners();
  }
}

class FooterButton extends StatefulWidget {
  final FooterButtonController controller;

  const FooterButton({super.key, required this.controller});

  @override
  State<FooterButton> createState() => _FooterButtonState();
}

class _FooterButtonState extends State<FooterButton> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Row(
      textDirection: TextDirection.rtl,
      children: [
        ElevatedButton(
          onPressed: () => widget.controller.onConfirm(),
          child: Text(widget.controller.confirmText),
        ),
        const SizedBox(width: 20),
        ElevatedButton(
          onPressed: () => widget.controller.onCanCel(),
          child: Text(widget.controller.cancelText),
        ),
      ],
    );
  }
}
